package com.logos.socket;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class InetAddressTest {

    public static void main(String[] args) throws UnknownHostException {
        // 获取InetAddress对象
        InetAddress inetAddress = InetAddress.getByName("192.168.157.1");
        System.out.println(inetAddress);
        // 获取主机名
        String hostName = inetAddress.getHostName();
        System.out.println(hostName);
        // 获取IP地址
        String hostAddress = inetAddress.getHostAddress();
        System.out.println(hostAddress);
    }
}
